package com.example.administrator.x2picturetransliteration.Home.Presenter.Activity;

import android.content.Context;

import com.example.administrator.x2picturetransliteration.Base.BasePresenter;
import com.example.administrator.x2picturetransliteration.Base.HttpGo;
import com.example.administrator.x2picturetransliteration.Bean.HttpDataBean;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import rx.subscriptions.CompositeSubscription;

/**
 * Created by Administrator on 2019/9/11.
 */

public class FeedbackPresenter extends BasePresenter{

    public FeedbackPresenter(Context context, CompositeSubscription mCompositeSubscription) {
        super(context, mCompositeSubscription);
    }

    /** 多文件上传 */
    public void multiUpload(List<String> url, final Callback mCallback){

        List<File> httpdata = new ArrayList<>();

        for (String path:url)httpdata.add(new File(path));

        mCompositeSubscription.add(

                mHttpGo.fileSubscription("file/multiUpload", httpdata, new HttpGo.HttpGoCallback() {
                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(HttpDataBean httpDataBean) {

                        if (httpDataBean.getCode()==0){

                            if (httpDataBean.getData()!=null)mCallback.getData(httpDataBean.getData());
                        }
                    }
                })
        );

    }

    /** 提交意见反馈 */
    public void add(Map<String,String> path, final Callback mCallback){

        mCompositeSubscription.add(

                mHttpGo.postSubscription( "user_feedback/add", path,"提交成功",new HttpGo.HttpGoCallback() {
                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(HttpDataBean httpDataBean) {

                        if (httpDataBean.getCode()==0){

                            mCallback.getData(null);
                        }
                    }
                })
        );

    }
}
